// import Vue from 'vue'
// import Vuex from 'vuex'

// Vue.use(Vuex)

// const store = new Vuex.Store({
//     state: {
//         cartList: []
//     },
//     mutations: {
//         addCounter(state, payload){
//             payload.count++
//         },
//         addToCart(state,payload){
//             state.cartList.push(payload)
//         }
//     },
//     actions: {
//         addCart(context, payload) {
//             let oldProduct = context.state.cartList.find(item => item.iid === payload.iid)
//             if(oldProduct) {
//                 // oldProduct.count += 1
//                 context.commit('addCounter', oldProduct)
//             } else{
//                 payload.count = 1
//                 context.commit('addToCart', payload)
//             }
            
//         }
//     }
// })

// export default store


import Vue from 'vue'
import Vuex from 'vuex'

import actions from './actions'
import mutations from './mutations'
import getters from './getters'

Vue.use(Vuex)

const state = {
  // 存储购物车中商品的数据
  cartList: [],
  usrInfo: JSON.parse(localStorage.getItem("usrInfo")) || [{
    usrname: '请登录账号',
    usrnum: '',
    pass: ''
  }],
  usr: JSON.parse(localStorage.getItem("usrInfo")) || {},
  orderList:[],
  islogin: false
}

export default new Vuex.Store({
  state,
  actions,
  mutations,
  getters,
  modules: {
  }
})
